package com.rem.photoablum.service;

import com.rem.photoablum.dao.UserDao;
import com.rem.photoablum.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author remembrance
 * @version 1.0
 * @date 2022/3/6 21:40
 */
@Service
public class UserService {
    @Autowired
    private UserDao userDao;

    public List<User> findAll(){
        return userDao.findAll();
    }
    public int updateUser(User user){
        return userDao.update(user.getUsername(),user.getPassword(),user.getId());
    }

    public User findByUsernameAndPassword(String username, String password) {
        return userDao.findByUsernameAndPassword(username, password);
    }

    public User findByUsername(String username) {
        return userDao.findByUsername(username);
    }

    public int addUser(User user){
        Integer id = (int)(Math.random() * 100000 + 1);
        return userDao.addUser(id,user.getUsername(),user.getPassword());
    }

    public int deleteUserById(Integer id){
        return userDao.deleteById(id);
    }
}